package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 护理计划
 */
@Api(tags = "护理计划")
@RestController
@RequestMapping("/nursing/plan")
public class NursingPlanController {

    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     * 查询所有护理计划
     *
     * @return
     */
    @ApiOperation("查询所有护理计划")
    @GetMapping
    public ResponseResult<NursingPlanVo> getAllPlan() {
        return ResponseResult.success(nursingPlanService.getAllPlan());
    }

    /**
     * 新增护理计划
     *
     * @param nursingPlanDto
     * @return
     */
    @ApiOperation("新增")
    @PostMapping
    public ResponseResult addPlan(
            @RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.addPlan(nursingPlanDto);
        return ResponseResult.success();
    }

    /**
     * 条件分页查询
     *
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ApiOperation("条件分页查询")
    @GetMapping("/search")
    public ResponseResult<PageResponse<NursingPlanVo>> getPage(
                                                                String name,
                                                                Integer status,
                                                                @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageResponse<NursingPlanVo> pageVo = nursingPlanService.getPage(name, status, pageNum, pageSize);
        return ResponseResult.success(pageVo);
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @ApiOperation("根据id查询")
    @GetMapping("/{id}")
    public ResponseResult<NursingPlanVo> getById(
                                    @PathVariable("id") Long id) {
        NursingPlanVo nursingPlanVo = nursingPlanService.getById(id);
        return ResponseResult.success(nursingPlanVo);
    }

    /**
     * 修改
     * @param id
     * @param nursingPlanDto
     * @return
     */
    @ApiOperation("修改")
    @PutMapping("/{id}")
    public ResponseResult updatePlan(
                                        @Param("id") Integer id,
                                        @RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.updatePlan(id,nursingPlanDto);
        return ResponseResult.success();
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public ResponseResult delPlan(@PathVariable Integer id){
        nursingPlanService.delPlan(id);
        return ResponseResult.success();
    }

    @ApiOperation("启用禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(@PathVariable Long id,
                                       @PathVariable Integer status){
        nursingPlanService.updateStatus(id,status);
        return ResponseResult.success();
    }
}
